<template>
  <div class="content">
    <el-card class="box-card">
      <el-form :model="shipModelMessage" label-width="120px">
        <el-form-item label="管理公司" class="form-box">
          <el-input
            v-model="shipModelMessage.company"
            placeholder="请输入管理公司"
          ></el-input>
        </el-form-item>
        <el-form-item label="管理公司地址" class="form-box">
          <el-input
            v-model="shipModelMessage.companyAddress"
            placeholder="请输入管理公司地址"
          ></el-input>
        </el-form-item>
        <el-form-item label="管理公司联系人" class="form-box">
          <el-input
            v-model="shipModelMessage.contact"
            placeholder="请输入管理公司联系人"
          ></el-input>
        </el-form-item>
        <el-form-item label="联系人电话" class="form-box">
          <el-input
            type="number"
            v-model="shipModelMessage.contactPhone"
            placeholder="请输入联系人电话"
          ></el-input>
        </el-form-item>
        <el-form-item label="联系人地址" class="form-box">
          <el-input
            v-model="shipModelMessage.contactAddress"
            placeholder="请输入联系人地址"
          ></el-input>
        </el-form-item>
        <el-form-item label="联系人传真" class="form-box">
          <el-input
            v-model="shipModelMessage.contactFax"
            placeholder="请输入联系人传真"
          ></el-input>
        </el-form-item>
        <el-form-item label="联系人邮箱" class="form-box">
          <el-input
            v-model="shipModelMessage.contactEmail"
            placeholder="请输入联系人邮箱"
          ></el-input>
        </el-form-item>
        <el-form-item label="联系人备注" class="form-box">
          <el-input
            type="textarea"
            v-model="shipModelMessage.contactRemark"
            placeholder="请输入联系人备注"
          ></el-input>
        </el-form-item>

        <div class="shipBottom">
          <el-button @click="clickCompany" type="primary">保存</el-button>
        </div>
      </el-form>
    </el-card>
  </div>
</template>
      
  <script>
import uiHeader from "../layout/UiHeader.vue";

export default {
  name: "corporateCenter",
  components: {
    uiHeader,
  },
  data() {
    return {
      shipModelMessage: {
        company: "",
        companyAddress: "",
        contact: "",
        contactPhone: "",
        contactAddress: "",
        contactFax: "",
        contactEmail: "",
        contactRemark: "",
      },
    };
  },
  mounted() {
    this.getLoginUser();
  },
  methods: {
    // 获取当前登陆人信息
    getLoginUser() {
      const that = this;
      that
        .$axios({
          method: "get",
          url: "/api/user/get-login-user",
        })
        .then(function (res) {
          if (res.data.code == 0) {
            that.shipModelMessage = {
              company: res.data.data.department.company,
              companyAddress: res.data.data.department.companyAddress,
              contact: res.data.data.department.contact,
              contactPhone: res.data.data.department.contactPhone,
              contactAddress: res.data.data.department.contactAddress,
              contactFax: res.data.data.department.contactFax,
              contactEmail: res.data.data.department.contactEmail,
              contactRemark: res.data.data.department.contactRemark,
            };
            console.log(that.shipModelMessage);
            console.log(res.data.data);
          }
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    clickCompany() {
      const that = this;
      const url = `/api/user/update-company-message?company=${that.shipModelMessage.company}&companyAddress=${that.shipModelMessage.companyAddress}&contact=${that.shipModelMessage.contact}&contactPhone=${that.shipModelMessage.contactPhone}&contactAddress=${that.shipModelMessage.contactAddress}&contactFax=${that.shipModelMessage.contactFax}&contactEmail=${that.shipModelMessage.contactEmail}&contactRemark=${that.shipModelMessage.contactRemark}`;
      console.log(that.shipModelMessage);
      that
        .$axios({
          method: "get",
          url: url,
        })
        .then(function (res) {
          if (res.data.code == 0) {
            that.getLoginUser();
            that.$message.success("操作成功！");
          }
        })
        .catch(function (error) {
          console.log(error);
        });
    },
  },
};
</script>
      <style>
.content {
  width: 100%;
}
.box-card {
  width: 100%;
  margin: 20px auto;
}
</style>